import axios from 'axios'

axios.interceptors.response.use((response: any): any => {
  response.res = response.err = null
  if (response.data.status === 0) {
    response.err = {
      code: response.data.status,
      msg: response.data.message,
      data: response.data.data
    }
  } else {
    response.res = {
      code: response.data.status,
      msg: response.data.message,
      data: response.data.data
    }
  }
  return response
}, (error: any): Promise<any> => {
  return Promise.reject(error)
  // error.res = null
  // error.err = {
  //   code: -10000,
  //   msg: '未知错误,请联系客服!'
  // }
  // return error
})

export default axios
